package com.xqls.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

import com.xqls.biz.LoginBiz;
import com.xqls.dal.model.Login;

/**
 *	权限工具包
 * @author Rock
 *
 */
public class PurviewUtil {
	
	/**
	 * 根据枚举MSG判断当前用户是否存在次权限
	 * @param dictionaryEnums 权限名称枚举
	 * @return 返回是否
	 */
	public static boolean getIsHavePurview(DictionaryEnums dictionaryEnums){
		Subject subject = SecurityUtils.getSubject();
		String username = subject.getPrincipal().toString();
		Map<String, Object> loginMap = new HashMap<String, Object>();
		loginMap.put("userName", username);
		LoginBiz loginBiz = (LoginBiz) ContextUtil.getBean(LoginBiz.class);
		List<Login> loginList = loginBiz.getLoginByMap(loginMap);
		for (Login login : loginList) {
			if(dictionaryEnums.getMsg().equals(login.getPermission().getPermName())){
				return true;
			}
		}
		return false;
	}
}
